<?php

namespace app\api\model;

use app\admin\model\Taocan;
use think\Model;
use think\Session;

class OrderModel extends Model
{

    // 表名
    protected $name = 'order';
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';

    public static function addorder($data){
        $newdata = [
            'user_id'=>$data['user_id'],
            'order_sn'=>$data['order_sn'],
            'subject_id'=>$data['subject_id'],
            'pay_type'=>$data['pay_type'],
            'taocan'=>isset($data['taocan']) ? $data['taocan'] : '',

        ];
        $order = new OrderModel();
        if($data['pay_type'] == 'card'){
            $newdata['day'] = $data['day'];
            $newdata['card_id'] = $data['card_id'];
        }else{
            $taoModel = new Taocan();
            $taodata = $taoModel::get($data['taocan']);
            $newdata['day'] = $taodata['day'];
        }
//        var_dump($newdata);die;
        $order->save($newdata);
        return $order->id;
    }
}
